package com.lxy.demo.controller;

import com.lxy.demo.service.UsersServce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Component
@RequestMapping("users")
public class UsersController {

    @Autowired
    private UsersServce usersServce;

    @RequestMapping("/login")
    public String login(String userCode, String password, Model model, HttpServletRequest request){
        System.out.println(userCode+password);
        boolean b = usersServce.selectUser(userCode, password);
        if(b){
            request.getSession().setAttribute("username",userCode);
            //model.addAttribute("username",userCode);
            return "forward:/type/find";
        }
        model.addAttribute("login","no");
        return "login";
    }

    @RequestMapping("/exit")
    private String exit(HttpServletRequest request){
        request.getSession().removeAttribute("username");
        return "login";
    }
}
